<?php
require('../../include/connectdb.php');
session_start();
if($_SESSION['login']==false){
	$_SESSION['error']="Cảnh báo: bạn phải đăng nhập trước khi vào phần quản trị trang web";
	header('location:../index.php');
}
$act=$_GET['act'];

if($act=='sta'){
	$ID=$_GET['ID'];
	$status=$_GET['St'];
	$sql="update lienhe set lhStatus=".$status." where lhId=".$ID;
	mysql_query($sql);
	header('location:../main.php?page=lcon');
}

if($act=='add'){
	$name=$_POST["name"];
	$yahoo=$_POST["yahoo"];
	$skype=$_POST["skype"];
	$sdt=$_POST["sdt"];
	$status=null;
	if($_POST['status']==true){
		$status=1;
	}else{
		$status=0;
	}
	$sql="insert lienhe(lhName,lhYahoo,lhSkype,lhSDT,lhStatus) values('".$name."','".$yahoo."','".$skype."','".$sdt."',".$status.")";
	mysql_query($sql);
	header("location:../main.php?page=lcon");
}

if($act=='edit'){
	$ID=$_GET['ID'];
	$name=$_POST["name"];
	$yahoo=$_POST["yahoo"];
	$skype=$_POST["skype"];
	$sdt=$_POST["sdt"];
	$status=null;
	if($_POST['status']==true){
		$status=1;
	}else{
		$status=0;
	}
	$sql="select * from lienhe where lhId=".$ID;
	$res=mysql_query($sql);
	$r=mysql_fetch_array($res);
	if($r['lhName']!=$name){
		$sql="update lienhe set ";
		$sql=$sql." lhName='".$name."'";
		$sql=$sql." where lhId=".$ID;
		mysql_query($sql);
	}
	if($r['lhYahoo']!=$yahoo){
		$sql="update lienhe set ";
		$sql=$sql." lhYahoo='".$yahoo."'";
		$sql=$sql." where lhId=".$ID;
		mysql_query($sql);
	}
	if($r['lhSkype']!=$skype){
		$sql="update lienhe set ";
		$sql=$sql." lhSkype='".$skype."'";
		$sql=$sql." where lhId=".$ID;
		mysql_query($sql);
	}
	if($r['lhSDT']!=$sdt){
		$sql="update lienhe set ";
		$sql=$sql." lhSDT='".$sdt."'";
		$sql=$sql." where lhId=".$ID;
		mysql_query($sql);
	}
	if($r['lhStatus']!=$status){
		$sql="update lienhe set ";
		$sql=$sql." lhStatus=".$status;
		$sql=$sql." where lhId=".$ID;
		mysql_query($sql);
	}
	header('location:../main.php?page=lcon');
}

if($act=='del'){
	$ID=$_GET['ID'];
	$sql="delete from lienhe where lhID=".$ID;
	mysql_query($sql);
	header('location:../main.php?page=lcon');
}
?>